const { addService, updateService, delService, listService, delAllService } = require('../service/todolist')

const add = async ctx => {
  const todo = ctx.request.body
  const data = await addService(todo)
  ctx.body = {
    code: 0,
    data
  }
}


const update = async ctx => {
  const body = ctx.request.body
  const data = await updateService(body)
  ctx.body = {
    code: 0,
    data
  }
}

const del = async ctx => {
  const { id } = ctx.query
  const data = await delService(id)
  ctx.body = {
    code: 0,
    data
  }
}

const delAll = async ctx => {
  const data = await delAllService()
  ctx.body = {
    code: 0,
    data
  }
}

const list = async ctx => {
    const data = await listService()
    ctx.body = {
      code: 0,
      data
    }
  }

module.exports = {
  add,
  update,
  del,
  list,
  delAll
}